import requests
import re
import os

root = "./images"
if not os.path.exists(root):
    os.mkdir(root)
small_root = os.path.join(root, "small_images")
if not os.path.exists(small_root):
    os.mkdir(small_root)
big_root = os.path.join(root, "big_images")
if not os.path.exists(big_root):
    os.mkdir(big_root)

url = "https://www.hdbz.net/"
response = requests.get(url)
html = response.content.decode()
imgs = re.findall(r'data-original="(.*?)" ',html)
num=0
for simg in imgs:
    ress = requests.get(simg)
    num+=1
    with open(f"{small_root}/small{num}.jpg",'wb') as f:
        f.write(ress.content)
        print(f'已保存小图small{num}.jpg')
    bimg = re.search(r'(.*?)\?',simg)
    resb = requests.get(bimg.group(1))
    with open(f"{big_root}/big{num}.jpg",'wb') as f:
        f.write(resb.content)
        print(f'已保存大图big{num}.jpg')

